package data_join;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class GoodsBean implements WritableComparable<GoodsBean> {
    // Order - order id
    private String oid;
    // Order|Item - item id
    private String gid;
    // Item - item name
    private String name;
    // Order - item amount
    private int amount;
    // store table type
    private String table;

    public GoodsBean() {
    }

    public String getOid() {
        return oid;
    }

    public void setOid(String oid) {
        this.oid = oid;
    }

    public String getGid() {
        return gid;
    }

    public void setGid(String gid) {
        this.gid = gid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    public String getTable() {
        return table;
    }

    public void setTable(String table) {
        this.table = table;
    }

    @Override
    public int compareTo(GoodsBean o) {
        int compare = this.getGid().compareTo(o.getGid());
        if (compare == 0) {
            return o.getName().compareTo(this.getName());
        } else {
            return compare;
        }
    }

    @Override
    public String toString() {
        return this.gid + " " + this.amount + " " + this.name;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(oid);
        out.writeUTF(gid);
        out.writeInt(amount);
        out.writeUTF(name);
        out.writeUTF(table);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        this.oid = in.readUTF();
        this.gid = in.readUTF();
        this.amount = in.readInt();
        this.name = in.readUTF();
        this.table = in.readUTF();
    }
}
